package com.it.service.impl;

import com.it.mapper.UserInfoMapper;
import com.it.pojo.UserInfo;
import com.it.pojo.UserInfoExample;
import com.it.pojo.vo.UserVo;
import com.it.service.UserInfoService;
import com.mysql.cj.util.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author: zgc
 * @version: 1.0
 * @description:
 * @date: 2023/12/21 9:52
 */
@Service
@Transactional
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public int addUserInfo(UserVo vo) {
        UserInfo userInfo = new UserInfo();
        BeanUtils.copyProperties(vo, userInfo);
        /*修改*/
        userInfo.setInfoCreatetime(new Date());
        return userInfoMapper.updateByPrimaryKeySelective(userInfo);

    }

    @Override
    public UserInfo getOneUserInfo(String userid) {
        return userInfoMapper.selectByPrimaryKey(userid);
    }

    @Override
    public List<UserInfo> findAll() {
        UserInfoExample example = new UserInfoExample();
        UserInfoExample.Criteria criteria = example.createCriteria();
        criteria.andInfoDelEqualTo(0);
        return userInfoMapper.selectByExample(example);
    }

    private String getPrimaryKey() {
        UserInfoExample example = new UserInfoExample();
        List<UserInfo> list = userInfoMapper.selectByExample(example);
        return list.size() + 1 + "";
    }

}
